/*
* Copyright (c) 2009 contentismissing.net, artifacts.de
*
* All rights reserved.
*
* Authors: Jens Lembke <j@contentismissing.net>;
*          Michael Markowski <m.markowski@artifacts.de>;
*
* All non-exclusive rights granted to Deutsche Telekom AG Laboratories
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/**
* TouchBehaviour - Superclass for all behaviour classes.
* A TouchBehaviour can handle arbitrary touch events dispatched by the manager
* and are used to affect the object position, rotation, scale, etc. when touched.
*/
package net.contentismissing.tlabs.cocktailparty.behaviours
{
	import de.artifacts.multitouch.TouchEvent;
	import de.artifacts.multitouch.behaviours.TwoFingerBehaviour;
	import flash.display. * ;
	import flash.events. * ;
	import flash.geom.Point;
	import net.contentismissing.tlabs.cocktailparty.ui.WhisperingArea;
	import net.contentismissing.tlabs.cocktailparty.model.Model;
	import net.contentismissing.tlabs.cocktailparty.ui.Workspace;
	import mx.core.Application;
	public class DrawBehaviour extends TwoFingerBehaviour
	{
		private var whisperingArea : WhisperingArea;
		public function DrawBehaviour(whisperingArea : WhisperingArea)
		{
			super();
			this.whisperingArea = whisperingArea;
		}

		override public function touchedHandler(event : TouchEvent) : void
		{
			super.touchedHandler(event);
			if (this.touchingCursors.length > 1) return;
			if (event.cursor == null) return;
			if (event.cursor.touchables.indexOf(touchable) > - 1)
			{
				var workspace : Workspace = Model.getInstance().currentWorkspace;
				this.whisperingArea = new WhisperingArea();
				whisperingArea.graphics.beginFill(0xff0000 , 0.5);
				whisperingArea.graphics.drawRect(0 , 0 , 1280 , 800);
				whisperingArea.graphics.endFill();
				workspace.addChild(whisperingArea);
				var x : int = event.cursor.position.x;
				var y : int = event.cursor.position.y;
				this.whisperingArea.startDrawingAt(new Point(x , y));
			}
		}

		override public function releasedHandler(event : TouchEvent) : void
		{
			this.whisperingArea.stopDrawing();
			var workspace : Workspace = Model.getInstance().currentWorkspace;
			workspace.removeChild(this.whisperingArea);
		}

		override public function repositionedHandler(event : TouchEvent) : void
		{
			super.repositionedHandler(event);
			if (event.cursor == null) return;
			var x : int = event.cursor.position.x;
			var y : int = event.cursor.position.y;
			this.whisperingArea.drawTo(new Point(x , y));
		}
	}
}
